<template>
  <div id="app">
    <Topbar :key="topbarkey"></Topbar>
    <Header></Header>
    <router-view @changeTopbarkey="changeTopbarkeyFn" />
    <Footer></Footer>
    <Login v-show="isShowModal"></Login>
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>

<script>
// 导入其他组件
import Topbar from "@/components/Topbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
// 接口
import { JingPinAPI, ReMenAPI } from "@/request/api.js";
// 辅助函数
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarkey: 5,
    };
  },
  methods: {
    changeTopbarkeyFn() {
      this.topbarkey++;
    },
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  // 发送请求 是异步 记得 async + await
  async created() {},
  computed: {
    ...mapState({
      isShowModal: (state) => state.ShowModal.isShowModal,
      isShowToast: (state) => state.ShowToast.isShowToast,
    }),
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        // 如果旧地址为 / 就不需要重载
        console.log("地址变化了");
        if (oldVal != "/") {
          this.topbarkey++;
        }
      },
    },
  },
};
</script>
<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
